<template>
	<div class="ffffff mainpadding radius" style="width: 75%;">
		<div class="flexleft">
			<div :class="tabActive==item.id?'active margin_right3 pointer':'noActive margin_right3 pointer'" v-for="(item,index) in tabList" :key="index" @click="changetab(item)">
				{{item.name}}
			</div>
		</div>
		<question-list :item="item" v-for="item in list.data" :key="item.id"></question-list>
		<div class="flexcenter margin_top" v-if="list.total > 15">
			<el-pagination background layout="prev, pager, next" :page-size="15" :total="list.total"
				@current-change="tuijianchange">
			</el-pagination>
		</div>
	</div>
</template>

<script>
	import questionList from "./components/questionList"
	import {
		getquestionlist
	} from "@/API/question"
	export default{
		components:{
			questionList
		},
		data(){
			return{
				tabActive:0,
				tabList: [{
					name: "全部",
					id:0
				}, {
					name: "待接单",
					id:3
				}, {
					name: "待回答",
					id:4
				}, {
					name: "已完成",
					id:5
				}],
				page: 1,
				list: {
					data: []
				},
			}
		},
		created() {
			this.$bus.$on("changelist",data=>{
				this.init(1)
			})
			this.init()
		},
		methods: {
			changetab(item){
				this.tabActive=item.id
				this.init(1)
			},
			init(page) {
				getquestionlist({
					page: page || 1,
					state: this.tabActive,
				}).then(res => {
					this.list = res.data.data
					this.list.data = res.data.data.data;
				})
			},
			// 推荐页码改变调用接口
			tuijianchange(val) {
				this.init(val)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.noActive {
		font-size: 15px;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}
	
	.active {
		font-size: 15px;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #3478F5;
		position: relative;
	}
	
	.active::after {
		content: '';
		width: 22px;
		height: 2px;
		background: #3478F5;
		border-radius: 6px 6px 6px 6px;
		position: absolute;
		left: 50%;
		transform: translateX(-50%);
		bottom: -10px;
	}
</style>